

--  SELECT * FROM ZDC_VI_SO_PROJECT_ITEM_SEL


IF EXISTS (SELECT name FROM sysobjects
WHERE name = 'ZDC_VI_SO_PROJECT_ITEM_SEL' AND type = 'V')
DROP VIEW ZDC_VI_SO_PROJECT_ITEM_SEL
GO

CREATE VIEW ZDC_VI_SO_PROJECT_ITEM_SEL

AS 

  
  SELECT S.ORG AS ORG
        ,ISNULL(SS.Project,0) AS PROJECT 
		,MIN(SL.ItemInfo_ItemID) AS ITEMID

  FROM SM_SO S 
  --LEFT JOIN Base_Organization G ON G.ID = S.Org 
  LEFT JOIN SM_SOLINE SL ON SL.SO = S.ID 
  LEFT JOIN SM_SOSHIPLINE SS ON SS.SOLine = SL.ID 
  LEFT JOIN CBO_Project P ON P.ID = ISNULL(SS.Project,0)
  WHERE ISNULL(SS.Project,0) > 0 
  GROUP BY S.ORG ,ISNULL(SS.Project,0)


 

